<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>管理投诉</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <table id="table1"></table><br>
    <a href="ManagerPage.jsp">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    $(function () {
        $.ajax({
            url: "http://localhost:8080/complaint.do",
            type: "post",
            data: {
                method: 'selectComplaint'
            },
            dataType: "text",
            success: function (data) {
                let parse = JSON.parse(data);
                if (parse.length === 0) {
                    alert("没有待处理的举报！");
                    window.location.href = 'ManagerPage.jsp';
                } else {
                    let table1 = document.querySelector('#table1');
                    for (let i = 0; i < parse.length; i++) {
                        if (parse[i].type === 1) {
                            let tr = document.createElement('tr');
                            tr.innerText = '投诉店铺'
                            table1.appendChild(tr);
                            let tr1 = document.createElement('tr');
                            table1.appendChild(tr1);
                            let th1 = document.createElement('th');
                            th1.innerText = '内容';
                            tr1.appendChild(th1);
                            let td1 = document.createElement('td');
                            td1.innerText = parse[i].content;
                            tr1.appendChild(td1);
                            let td2 =document.createElement('td');
                            tr1.appendChild(td2);
                            let a = document.createElement('a');
                            a.innerText = '已处理，去删除';
                            a.href = 'DeleteComplaint.jsp?complaintId='+parse[i].complaintId;
                            td2.appendChild(a);
                        }
                        if (parse[i].type === 2) {
                            let tr = document.createElement('tr');
                            table1.appendChild(tr);
                            tr.innerText = '投诉系统';
                            let tr1 = document.createElement('tr');
                            table1.appendChild(tr1);
                            let th1 = document.createElement('th');
                            th1.innerText = '内容';
                            tr1.appendChild(th1);
                            let td1 = document.createElement('td');
                            td1.innerText = parse[i].content;
                            tr1.appendChild(td1);
                            let td2 =document.createElement('td');
                            tr1.appendChild(td2);
                            let a = document.createElement('a');
                            a.innerText = '已处理，去删除';
                            a.href = 'DeleteComplaint.jsp?complaintId='+parse[i].complaintId;
                            td2.appendChild(a);
                        }
                    }
                }
            }
        })
    })
</script>
</body>
</html>
